//
//  AvatarTableViewCell.m
//  NuwaRobot
//
//  Created by Kendama on 2017/11/30.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import "AvatarTableViewCell.h"

NSString *const kAvatarTableViewCellIdentifier = @"kAvatarTableViewCellIdentifier";

@implementation AvatarTableViewCell

+ (instancetype)dequeueReusableWithTableView:(UITableView *)tableView
{
    AvatarTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kAvatarTableViewCellIdentifier];
    if (cell == nil)
    {
        cell = [[AvatarTableViewCell alloc]init];
    }
    return cell;
}

- (instancetype)init
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kAvatarTableViewCellIdentifier];
    if (self)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = cellBackgroundColor;
        [self masLayoutSubview];
    }
    return self;
}

- (UIImageView *)avatarImageView
{
    if(!_avatarImageView)
    {
        UIView *superView = self.contentView;
        _avatarImageView = [[UIImageView alloc]init];
        [superView addSubview:_avatarImageView];
        _avatarImageView.layer.cornerRadius = px1920Height(150)/2;
        _avatarImageView.layer.masksToBounds = YES;
    }
    return _avatarImageView;
}
- (UILabel *)titleLabel
{
    if(!_titleLabel)
    {
        UIView *superView = self.contentView;
        _titleLabel = [[UILabel alloc]init];
        [superView addSubview:_titleLabel];
        [_titleLabel setFont:fontCommonSize];
        [_titleLabel setTextColor:[UIColor whiteColor]];
    }
    return _titleLabel;
}

- (UIImageView *)rightImageView
{
    if(!_rightImageView)
    {
        UIView *superView = self.contentView;
        _rightImageView = [[UIImageView alloc]init];
        [superView addSubview:_rightImageView];
        _rightImageView.image = [UIImage imageNamed:@"enter"];
    }
    return _rightImageView;
}


- (void)masLayoutSubview
{
    __weak UIView *superView = self.contentView;
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.left.mas_equalTo(superView.mas_left).with.offset(px1920Height(40));
        make.width.mas_equalTo(px1080Width(300));
    }];
    
    [self.rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.right.mas_equalTo(superView.mas_right).with.offset(-px1920Height(40));
        make.height.mas_equalTo(px1920Height(35));
        make.width.mas_equalTo(px1920Height(20));
    }];
    
    [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.right.mas_equalTo(self.rightImageView.mas_left).with.offset(-px1080Width(40));
        make.height.width.mas_equalTo(px1920Height(150));
    }];
    
    UIView *lineView = ({
        lineView = [[UIView alloc]init];
        [superView addSubview:lineView];
        lineView.backgroundColor = rgba(6,27,56,1);
        [lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(superView.mas_bottom);
            make.left.right.mas_equalTo(superView);
            make.height.mas_equalTo(px1920Height(1));
        }];
        lineView;
        
    });
}

@end
